package com.gxc.mall.user.mq;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.gxc.mall.user.config.TestRabbitQueueConfigBean;
import com.gxc.mall.user.entity.UserEntity;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @author GongXincheng
 * @since 2019-09-09 11:15
 */
@Component
public class TestMqConsumer {

    private final ObjectMapper objectMapper = new ObjectMapper();

    @RabbitListener(queues = TestRabbitQueueConfigBean.TEST_MESSAGE_OBJECT_QUEUE_NAME)
    public void receiveMessageObject(@Payload String message) throws IOException {
//        String message = new String(body, StandardCharsets.UTF_8);
        System.out.println(objectMapper.readValue(message, UserEntity.class));
    }

}
